package com.yjt.fresh.activity;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.HttpManager;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.listener.HttpOnNextListener;
import com.yjt.fresh.R;
import com.yjt.fresh.api.ApiGetUserInfo;
import com.yjt.fresh.base.BaseSimpleActivity;
import com.yjt.fresh.bean.BeanUserInfo;
import com.yjt.fresh.utils.PreferenceManager;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AtyMyWallet extends BaseSimpleActivity {
    private static final int REQUEST_CODE = 1009;
    @BindView(R.id.back)
    RelativeLayout mBack;
    @BindView(R.id.tv_app_aty_my_wallet_detail)
    TextView mTvDetail;
    @BindView(R.id.tv_app_aty_my_wallet_money)
    TextView mTvMoney;
    @BindView(R.id.rl_app_aty_my_wallet_recharge_online)
    RelativeLayout mRlRechargeOnline;
    @BindView(R.id.rl_app_aty_my_wallet_recharge_card)
    RelativeLayout mRlRechargeCard;
    @BindView(R.id.rl_app_aty_my_wallet_my_card)
    RelativeLayout mRlMyCard;
    @BindView(R.id.rl_app_aty_my_wallet_buy_card)
    RelativeLayout mRlBuyCard;


    @Override
    protected int getContentView() {
        return R.layout.app_aty_my_wallet;
    }

    @Override
    protected void initViews() {
        ButterKnife.bind(this);
        mTvMoney.setText(PreferenceManager.getInstance().getRestMoney()+"元");
    }

    @Override
    protected void initEvent() {
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        mTvDetail.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyMyWalletDetail.class);
                startActivity(intent);
            }
        });

        mRlRechargeOnline.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyRechargeOnline.class);
                startActivityForResult(intent,REQUEST_CODE);
            }
        });

        mRlRechargeCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyRechargeByCard.class);
                startActivityForResult(intent,REQUEST_CODE);
            }
        });

        mRlMyCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyMyCard.class);
                startActivity(intent);
            }
        });

        mRlBuyCard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,AtyBuyCard.class);
                startActivity(intent);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == REQUEST_CODE){
            if (PreferenceManager.getInstance().getIsLogin()) {
                getUserInfo();
            }
        }
    }

    private void getUserInfo() {
        ApiGetUserInfo apiGetUserInfo = new ApiGetUserInfo(new HttpOnNextListener<BeanUserInfo>() {
            @Override
            public void onNext(BeanUserInfo beanUserInfo) {
                mTvMoney.setText(beanUserInfo.getYU_MONEY());
            }

            @Override
            public void onReLogin() {

            }
        }, mContext, true, false, true);
        apiGetUserInfo.setSession_id(PreferenceManager.getInstance().getUserInfo().getSESSION_ID());
        HttpManager.getInstance().doHttpDeal(apiGetUserInfo);
    }
}
